<template>
  <el-link type="danger" @click="deleteAnnc">删除</el-link>
</template>

<script>
export default {
  name: 'DeleteAnnouncementLink', // 删除公告按钮
  props: {
    annc: { // 公告数据
      type: Object,
      required: true,
    },
  },
  methods: {
    // 删除公告
    deleteAnnc() {
      this.$msgbox({
        title: '提示',
        message: '确认删除这份公告吗？',
        showCancelButton: true, // 显示取消按钮
        customClass: 'confirm-left',
        confirmButtonText: '确定',
        confirmButtonLoading: false,
        confirmButtonClass: 'el-button--danger',
        cancelButtonText: '取消',
        type: 'warning',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            Object.assign(instance, {
              confirmButtonLoading: true,
              confirmButtonText: '正在删除...',
            });
            this.$api.announcements.delete({ anncId: this.annc.id })
              .then(() => {
                this.$message.success('删除成功');
                this.$emit('deletedAnnc', this.annc);
              })
              .catch(() => {})
              .then(() => done());
          } else done();
        },
      });
    },
  },
};
</script>

<style></style>
